from django.shortcuts import render, redirect
from .import models


# Create your views here.
def index(request):
    return render(request, 'index.html')

def login(request):
    if request.method == 'GET':
        # 用户初次进入展示登录表单
        return render(request, 'login.html')
    elif request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        # 查询数据库     'select * from login_user where name=%s and password=%s' % (username,password)
        user = models.User.objects.filter(name=username, passworld=password).first()
        if not user:
            print('用户未注册,或密码错误')
            return redirect('/login/')

        # print(username, password)
        # 登录成功
        print('登录成功')
        return redirect('/index/')
def register(request):

    pass
def logout(request):
    pass